package com.martian.service.token;

import com.martian.common.constant.TokenInfo;
import com.martian.service.redis.RedisRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author martian
 * @version V1.0.0
 * @Description
 * @date 2023-03-24 16:53
 */
@Service
public class TokenServiceImpl implements TokenService {

    @Resource
    private RedisRepository redisRepository;

    @Override
    public TokenInfo getTokenInfo(String accessToken) {
        String userId = redisRepository.selectAccessToken(accessToken);
        if (userId != null) {
            TokenInfo tokenInfo = new TokenInfo();
            tokenInfo.setUserId(Integer.valueOf(userId));
            tokenInfo.setAccessToken(accessToken);
            return tokenInfo;
        }
        return null;
    }

    @Override
    public TokenInfo getManagerTokenInfo(String accessToken) {
        String managerId = redisRepository.selectManagerLoginIdByToken(accessToken);
        if (managerId != null) {
            TokenInfo tokenInfo = new TokenInfo();
            tokenInfo.setUserId(Integer.valueOf(managerId));
            tokenInfo.setAccessToken(accessToken);
            return tokenInfo;
        }
        return null;
    }
}
